﻿<UserControl x:Class="ModernAudioTagger.Content.ContentNetwork"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             xmlns:helpers="clr-namespace:ModernAudioTagger.Helpers"
             xmlns:validation="clr-namespace:ModernAudioTagger.Validation"
             xmlns:settings="clr-namespace:ModernAudioTagger.Settings"
             xmlns:provider="clr-namespace:ModernAudioTagger.Provider"
             xmlns:view="clr-namespace:ModernAudioTagger.View"
             mc:Ignorable="d" 
             d:DesignHeight="400" d:DesignWidth="300">
    
    <UserControl.DataContext>
        <Binding Source="{x:Static provider:ViewModelLocator.Instance}" Path="NetworkVM" />
    </UserControl.DataContext>
    
    <DockPanel>
        <StackPanel Orientation="Horizontal" DockPanel.Dock="Top" HorizontalAlignment="Left">
            <mui:ModernButton 
                    ToolTip="Check for updates"
                    Command="{Binding CheckAppUpdatesCommand}"                
                    EllipseDiameter="30" IconWidth="16" IconHeight="16"                           
                    VerticalAlignment="Top"                    
                    IconData="F1 M 38,30.0833C 39.7489,30.0833 41.1667,31.5011 41.1667,33.25C 41.1667,34.9989 39.7489,36.4167 38,36.4167C 36.2511,36.4167 34.8333,34.9989 34.8333,33.25C 34.8333,31.5011 36.2511,30.0833 38,30.0833 Z M 40.5749,38.6155L 43.5416,57L 32.4583,57L 35.4251,38.6155L 40.5749,38.6155 Z M 55.4167,33.25C 55.4167,37.3117 54.0263,41.0486 51.6956,44.0109L 49.2055,42.0544C 51.1124,39.6307 52.25,36.5732 52.25,33.25C 52.25,29.9268 51.1124,26.8693 49.2055,24.4457L 51.6956,22.4892C 54.0263,25.4514 55.4167,29.1883 55.4167,33.25 Z M 24.3044,44.0109C 21.9737,41.0486 20.5833,37.3117 20.5833,33.25C 20.5833,29.1883 21.9737,25.4514 24.3044,22.4891L 26.7945,24.4457C 24.8875,26.8693 23.75,29.9268 23.75,33.25C 23.75,36.5732 24.8875,39.6307 26.7945,42.0543L 24.3044,44.0109 Z M 46.7154,26.4022C 48.1986,28.2873 49.0833,30.6653 49.0833,33.25C 49.0833,35.8347 48.1986,38.2128 46.7154,40.0978L 44.2253,38.1413C 45.2847,36.7948 45.9167,35.0962 45.9167,33.25C 45.9167,31.4038 45.2847,29.7052 44.2253,28.3587L 46.7154,26.4022 Z M 29.2846,40.0978C 27.8014,38.2127 26.9167,35.8347 26.9167,33.25C 26.9167,30.6653 27.8014,28.2872 29.2846,26.4022L 31.7747,28.3587C 30.7153,29.7052 30.0833,31.4038 30.0833,33.25C 30.0833,35.0962 30.7153,36.7948 31.7747,38.1413L 29.2846,40.0978 Z "
                    >

                <!---->
                    <!--IconData="F1 M 53,49C 55.2091,49 57,50.7909 57,53C 57,55.2091 55.2091,57 53,57C 50.7909,57 49,55.2091 49,53C 49,50.7909 50.7909,49 53,49 Z M 57,24C 38.7746,24 24,38.7746 24,57L 19,57C 19,36.0132 36.0132,19 57,19L 57,24 Z M 57,34C 44.2974,34 34,44.2975 34,57L 29,57C 29,41.536 41.536,29 57,29L 57,34 Z M 57,44C 49.8203,44 44,49.8203 44,57L 39,57C 39,47.0589 47.0589,39 57,39L 57,44 Z "-->
                <mui:ModernButton.CommandParameter>
                    <sys:Boolean>True</sys:Boolean>
                </mui:ModernButton.CommandParameter>
            </mui:ModernButton>
        </StackPanel>
        <Grid DockPanel.Dock="Bottom">
            <ScrollViewer>
                <StackPanel HorizontalAlignment="Left" helpers:NotifierPanelHelper.EnableNotifier="True">
                    <CheckBox IsChecked="{Binding Path=EnableProxy, Mode=TwoWay}" HorizontalAlignment="Center" Margin="6">Enable Proxy</CheckBox>
                    <!--<CheckBox HorizontalAlignment="Center" Margin="6" Content="Enable Proxy">
                    <CheckBox.IsChecked>
                        <helpers:CustomBinding Path="EnableProxy" Source="{StaticResource networksettings}" Mode="TwoWay" />
                    </CheckBox.IsChecked>
                </CheckBox>-->
                    <TextBlock Style="{StaticResource Heading2}" Margin="{StaticResource DefaultLeftMargin}" HorizontalAlignment="Center">PROXY</TextBlock>
                    <TextBlock Style="{StaticResource Heading2}" Margin="{StaticResource DefaultLeftMargin}">HOST</TextBlock>
                    <TextBox Text="{Binding Path=Host, Mode=TwoWay}" Margin="{StaticResource DefaultTopLeftMargin}" Width="{StaticResource DefaultTextBoxWidth}"></TextBox>
                    <TextBlock Style="{StaticResource Heading2}" Margin="{StaticResource DefaultTopLeftMargin}">PORT</TextBlock>
                    <TextBox x:Name="txtPort" Margin="{StaticResource DefaultTopLeftMargin}" Width="80" HorizontalAlignment="Left">
                        <TextBox.Text>
                            <Binding Path="Port" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" NotifyOnValidationError="True">
                                <Binding.ValidationRules>
                                    <validation:NumberValidation />
                                </Binding.ValidationRules>
                            </Binding>
                        </TextBox.Text>
                    </TextBox>
                    <TextBlock Style="{StaticResource Heading2}" Margin="{StaticResource DefaultLeftMargin}" HorizontalAlignment="Center">CREDENTIALS</TextBlock>
                    <TextBlock Style="{StaticResource Heading2}" Margin="{StaticResource DefaultLeftMargin}">USER</TextBlock>
                    <TextBox Text="{Binding Path=User, Mode=TwoWay}" Margin="{StaticResource DefaultTopLeftMargin}" Width="{StaticResource DefaultTextBoxWidth}"></TextBox>
                    <TextBlock Style="{StaticResource Heading2}" Margin="{StaticResource DefaultLeftMargin}">PASSWORD</TextBlock>
                    <PasswordBox 
                    Margin="{StaticResource DefaultLeftMargin}"
                    helpers:PasswordHelper.Attach="True" 
                    helpers:PasswordHelper.Password="{Binding Path=Password, Mode=TwoWay}" Width="{StaticResource DefaultTextBoxWidth}" />
                    <TextBlock Style="{StaticResource Heading2}" Margin="{StaticResource DefaultLeftMargin}" Width="300">DOMAIN</TextBlock>
                    <TextBox Text="{Binding Path=Domain, Mode=TwoWay}" Margin="{StaticResource DefaultTopLeftMargin}" Width="{StaticResource DefaultTextBoxWidth}"></TextBox>
                    <StackPanel Orientation="Horizontal" Margin="0, 12, 0, 0">
                        <Button x:Name="savebtn" IsEnabled="False" Content="Save" Command="{Binding Source={x:Static settings:SettingsManager.Instance},  Path=SaveNetworkCommand}"  />
                        <Button x:Name="reloadbtn"  IsEnabled="False" Content="Reload" Command="{Binding Source={x:Static settings:SettingsManager.Instance},  Path=LoadNetworkCommand}" CommandParameter="{Binding}" Margin="{StaticResource DefaultLeftMargin}" />
                    </StackPanel>
                </StackPanel>
            </ScrollViewer>
        </Grid>
    </DockPanel>

    <i:Interaction.Triggers>
        <!-- changed elements in notifier panel event -->
        <helpers:RoutedEventTrigger RoutedEvent="{x:Static helpers:NotifierPanelHelper.ChildrenChangedEvent}">
            <ei:ChangePropertyAction TargetName="savebtn" PropertyName="IsEnabled" Value="True" />
            <ei:ChangePropertyAction TargetName="reloadbtn" PropertyName="IsEnabled" Value="True" />
            <!--<i:InvokeCommandAction Command="{Binding ProxyChangedCommand}" />-->
        </helpers:RoutedEventTrigger>

        <!-- check updates event -->
        <!--<i:EventTrigger EventName="SoftwareOutOfDateEvent" SourceObject="{Binding}">
            <i:Interaction.Behaviors>
                <helpers:EventTriggerBehavior Attacher="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window} }}" />
            </i:Interaction.Behaviors>
            <view:InvokeDelegateCommandAction 
                Command="{x:Static view:ViewCommands.ShowMessageOutOfDateVersionCommand}" 
                CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=InvokeParameter}" 
                />
        </i:EventTrigger>-->
        <i:EventTrigger EventName="SoftwareUpToDateEvent" SourceObject="{Binding}">
            <!--<i:Interaction.Behaviors>
                <helpers:EventTriggerBehavior Attacher="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window} }}" />
            </i:Interaction.Behaviors>-->
            <helpers:ShowMessageBoxAction Message="{StaticResource softwareUpToDateMessage}" Title="Info" />
        </i:EventTrigger>
        <i:EventTrigger EventName="NetworkErrorEvent" SourceObject="{Binding}">
            <!--<i:Interaction.Behaviors>
                <helpers:EventTriggerBehavior Attacher="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window} }}" />
            </i:Interaction.Behaviors>-->
            <helpers:ShowMessageBoxAction Message="{StaticResource networkErrorMessage}" Title="Error" />
        </i:EventTrigger>

        <!-- settings event -->
        <i:EventTrigger EventName="SettingsSaved" SourceObject="{x:Static settings:SettingsManager.Instance}">
            <ei:ChangePropertyAction TargetName="savebtn" PropertyName="IsEnabled" Value="False" />
            <ei:ChangePropertyAction TargetName="reloadbtn" PropertyName="IsEnabled" Value="False" />
        </i:EventTrigger>
        <i:EventTrigger EventName="SettingsReloaded" SourceObject="{x:Static settings:SettingsManager.Instance}">
            <ei:ChangePropertyAction TargetName="savebtn" PropertyName="IsEnabled" Value="False" />
            <ei:ChangePropertyAction TargetName="reloadbtn" PropertyName="IsEnabled" Value="False" />
        </i:EventTrigger>        
        
    </i:Interaction.Triggers>

</UserControl>
